package com.ricky.constencrypt.plugin

import com.android.build.gradle.AppExtension
import org.gradle.api.Plugin
import org.gradle.api.Project

open class ConstEncryptExtension(
    var enable: Boolean = false,
    var secretKey: String = ""
)

class ConstEncryptPlugin : Plugin<Project> {
    companion object {
        var enable = false
    }

    override fun apply(project: Project) {
        val extension = project.extensions.create("constencrypt", ConstEncryptExtension::class.java)
        project.extensions.getByType(AppExtension::class.java)
            .registerTransform(ConstEncryptTransform(project))
        project.gradle.projectsEvaluated {
            enable = extension.enable
            val secretKey = extension.secretKey
            if (enable && secretKey.isBlank()) throw IllegalArgumentException("请配置constencrypt secretKey")
            AESUtil.setSecretKey(secretKey)
        }
    }
}